/**
 * 
 */
package net.toocruel.iqismart.service.core.impl;


import net.toocruel.iqismart.dao.core.*;
import net.toocruel.iqismart.entity.core.Recommendation;
import net.toocruel.iqismart.service.core.RecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author toocruel
 *
 */
@Service
@Transactional
public class RecommendationServiceImpl implements RecommendationService {
    @Autowired
    private TagRepository tagRepository;

    @Autowired
    private CategoryRepository categoryRepository;

    @Autowired
    private SupportRepository supportRepository;

    @Autowired
    private QuestionRepository questionRepository;

    @Autowired
    private AnswerRepository answerRepository;

    @Autowired
    private CommentRepository commentRepository;

    @Autowired
    private ArticleRepository articleRepository;

    @Autowired
    private RecommendationRepository recommendationRepository;

    @Override
    public List<Recommendation> getLatestRecommendations(int count) {
        return recommendationRepository.findAll(new PageRequest(0,count,new Sort(Sort.Direction.ASC,"sort").and(new Sort(Sort.Direction.DESC,"id")))).getContent();
    }

    @Override
    public Recommendation postRecommendation(Recommendation recommendation) {
        return recommendationRepository.save(recommendation);
    }
}
